package cn.com.nwpu.visual_system.service.impl;

import cn.com.nwpu.visual_system.entity.ConfigData;
import cn.com.nwpu.visual_system.entity.CurrentInfo;
import cn.com.nwpu.visual_system.entity.Reactor;
import cn.com.nwpu.visual_system.mapper.CurrentInfoMapper;
import cn.com.nwpu.visual_system.mapper.ReactorMapper;
import cn.com.nwpu.visual_system.vo.CurrentInfoVo;
import cn.com.nwpu.visual_system.mapper.ConfigDataMapper;
import cn.com.nwpu.visual_system.service.CurrentInfoService;
import cn.com.nwpu.visual_system.vo.ToVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * @author Hutengzhong
 * @version 1.0.0
 * @title CurrentInfoServiceImpl
 * @description TODO
 * @date 2024/4/28 14:17
 */
@Service
public class CurrentInfoServiceImpl implements CurrentInfoService {
    @Autowired
    CurrentInfoMapper currentInfoMapper;
    @Autowired
    ConfigDataMapper configDataMapper;
    @Autowired
    ReactorMapper reactorMapper;
    @Override
    public List<CurrentInfoVo> getCurrentInfoByReactorId() {
        // 获取当前数据的最新值
        ConfigData configData = configDataMapper.getCurrentDataId();
        Integer currentDataId = Integer.parseInt(configData.getConfigValue());
        List<CurrentInfo> currentInfoList = currentInfoMapper.getReactorCurrentInfoList(currentDataId);

        // 每次访问后，自动加一，模拟实时数据（用id的递增代替时间的增加）
        Integer count = configDataMapper.updateCurrentDataId(currentDataId % 960 + 1);
        List<CurrentInfoVo> currentInfoVoList = ToVo.toCurrentInfoVo(currentInfoList);
        return currentInfoVoList;
    }
}
